package com.system.outpatientsystem.controller;

import com.system.outpatientsystem.pojo.Result;
import com.system.outpatientsystem.pojo.User;
import com.system.outpatientsystem.pojo.record_table;
import com.system.outpatientsystem.service.RecordService;
import com.system.outpatientsystem.service.UserService;
import com.system.outpatientsystem.utils.JwtUtils;
import com.system.outpatientsystem.utils.MD5Utils;
import com.system.outpatientsystem.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/record")
public class RecordController {

    @Autowired
    private RecordService recordService;

    //通过病历单id查询
    @PutMapping("/findById")
    public Result <record_table> findById(@RequestBody Map<String,Integer> ppp){
        Integer id=ppp.get("id");
        System.out.println(id);
        System.out.println(recordService.findById(id));
        record_table byId = recordService.findById(id);
        return Result.success(byId);
    }


//    通过病人id查找病历单
    @PutMapping("/findByUserId")
    public Result <List<record_table>> findByUserId(@RequestBody record_table table){
        int id=table.getUserId();
        return Result.success(recordService.findByUserId(id)) ;
    }

    @PostMapping("/insert")
    public Result recordInsert(@RequestBody record_table table){
        recordService.recordInsert(table);
        return Result.success();
    }

    @PutMapping("/update")
    public Result recordUpdate(@RequestBody record_table table){
        String c= table.getContent();
        String a=table.getApply();
        String f= table.getFormulation();
        Integer f_p= table.getFormulationPrice();
        Integer p_s=table.getPayStatus();
        Integer r_s=table.getRefundStatus();
        Integer v_s= table.getVisitStatus();
        record_table re=recordService.findById(table.getId());
        re.setContent(c);
        re.setApply(a);
        re.setFormulation(f);
        re.setFormulationPrice(f_p);
        re.setPayStatus(p_s);
        re.setRefundStatus(r_s);
        int visit_status=re.getVisitStatus();
        if(visit_status==1){
            return Result.error("病人已就诊");
        }
        re.setVisitStatus(v_s);
        recordService.recordUpdate(re);
        return Result.success(re);
    }




}
